﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Jugg.Core.Data;
using Jugg.Entities;
using System.Web;

namespace Jugg.Services.ActivityLog
{
    public class ActivityLogService : IActivityLogService
    {
        private const string MODEL_KEY = "JUGGUSERID";

        private IRepository<Entities.ActivityLog> _activityLogRepository;

        public ActivityLogService(IRepository<Entities.ActivityLog> activityLogRepository)
        {
            this._activityLogRepository = activityLogRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Guid getUserItem()
        {
            Guid userId = Guid.Empty;
            var userItem = HttpContext.Current.Items[MODEL_KEY];
            if (userItem != null)
                return (Guid)userItem;
            return Guid.Empty;
        }

        /// <summary>
        /// 插入实体更新日志
        /// </summary>
        /// <param name="log"></param>
        public void InsertActivityLog(Entities.ActivityLog log)
        {
            _activityLogRepository.insert(log);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        public void setUserItem(Guid userId)
        {
            HttpContext.Current.Items[MODEL_KEY] = userId;
        }
    }
}
